#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll t,n;
ll pre[1000010];
const ll maxn=1000000;
ll f(ll x){
    if(x%7==0)return 0;
    ll num=x;
    while(num){
        if((num%10)==7)return 0;
        num/=10;
    }
    return x*x;
}
void init(){
    for(ll i=1;i<=maxn;i++){
        pre[i]=pre[i-1]+f(i);
    }
}
int main()
{
    IOS;
    init();
    cin>>t;
    while(t--){
        cin>>n;
        cout<<pre[n]<<endl;
    }   
    getchar();
    getchar();
    return 0;
}
